function[x,output]=agent1maxrho_rov_15_Feb(x0, index,ewsb,waut,bind);
global P beta n m S state agent gammagrid  Y lowerbound rho table ScaleRov

objval = [];
output= [];
options =optimset('LargeScale','on','Display','off','Algorithm','active-set','MaxFunEvals',80000,'MaxIter',10000);
[x,fval,exitflag]=fmincon(@objfun,x0,[],[],[],[],[],[],@constrfun,options);
output(3)=exitflag;
function f = objfun(x)

i=index(1);
j=index(2);
cons = x(1);
gammarfun=(Y(j)-cons)/cons/ScaleRov;
if gammarfun>=gammagrid(1,4)
gammarfun=gammagrid(1,4)-eps;   
elseif gammarfun<=gammagrid(n,4)
gammarfun=gammagrid(n,4)+eps;
end
for g=1:agent
wint(g)=interp1(gammagrid(:,4),ewsb(:,j,g),gammarfun);
%wint(g)=interpolation1(scalefactor*ewsb, gammarfun, g,j);
end;


output(1)=utility(rho,cons)+beta*wint(1);
output(2)=utility(rho,(Y(j)-cons)/ScaleRov)+beta*wint(2);
objval = gammagrid(i,1:agent)*output';
f=-objval;
end

function [cineq,ceq]=constrfun(x);

i=index(1);
j=index(2);
cons = x(1);
gammarfun=(Y(j)-cons)/cons/ScaleRov;

ceq(1) = (waut(j,bind) - output(bind));
%ceq(2) =(cons-Y(j));
%cineq=[];
cineq(1)=(cons-Y(j));
cineq(2)=(waut(j,2-bind+1) - output(2-bind+1));
end
end
